package me.yxy.mobanddd.components.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.reflect.MethodSignature;

import java.lang.reflect.Method;

/**
 * AOP基础类，封装一些常用方法
 */
public class BaseAspect {

    /**
     * 获取当前拦截的类与方法信息
     * @param pjp
     * @return
     */
    protected ClassEntry getCurrentClassInfo(JoinPoint pjp) {
        Signature signature = pjp.getSignature();
        MethodSignature ms = (MethodSignature)signature;
        Method targetMethod = ms.getMethod();
        Method realMethod;
        try {
            realMethod = pjp.getTarget().getClass().getDeclaredMethod(signature.getName(), targetMethod.getParameterTypes());
        } catch (NoSuchMethodException e) {
            return null;
        }
        ClassEntry entry = new ClassEntry();
        entry.method = realMethod;
        entry.clz = pjp.getTarget().getClass();
        return entry;
    }

    //结构体
    protected static class ClassEntry{
        Class<?> clz;
        Method method;

    }


}
